/**
 * 
 */
package com.eis.util;

import org.apache.commons.codec.binary.Base64;
import org.apache.commons.codec.digest.DigestUtils;



/**
 * @author sh-panwei01
 *
 */
public class EncryptUtil {
	public static String encryptPassword(String password) {
		// MD5 encrypt
		String md5Encode = DigestUtils.md5Hex(password);
		// Base64 encode
		return Base64.encodeBase64String(md5Encode.getBytes());
	}
	
	public static boolean checkPassword(String inputPassword, String realPassword) {
		inputPassword = new String(Base64.decodeBase64(inputPassword));
		
		if (realPassword != null && realPassword.length() > 0) {
			return realPassword.equals(encryptPassword(inputPassword));
		} else {
			return true;
		}
	}
	
	public static String base64Encode(String str) {
		if (str != null) {
			return Base64.encodeBase64String(str.getBytes());
		} else {
			return null;
		}
	}
}
